package com.mutual.assistance.task.feignclient;

import com.mutual.assistance.response.R;
import com.mutual.assistance.task.model.dto.UserRemote;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author chenyuxin
 * @version 1.0
 * @description 熔断远程调用操作
 * @date 2023/2/10 16:37
 */
@Slf4j
@Component
public class UserServiceClientFallbackFactory implements FallbackFactory<UserServiceClient> {

    @Override
    public UserServiceClient create(Throwable throwable) {
        return new UserServiceClient() {
            @Override
            public R<String> subCredit(String username, Integer credit) {
                throwable.printStackTrace();
                log.error("发送熔断了");
                log.debug("调用搜索服务发生熔断降级方法，熔断异常：{}", throwable.getMessage());
                log.debug("username：{}， credit：{}", username, credit);
                return null;
            }

            @Override
            public R<String> rollbackCredit(String username, Integer credit) {
                throwable.printStackTrace();
                log.error("发送熔断了");
                log.debug("调用搜索服务发生熔断降级方法，熔断异常：{}", throwable.getMessage());
                log.debug("username：{}， credit：{}", username, credit);
                return null;
            }

            @Override
            public R<UserRemote> getPublishMessage(String username) {
                throwable.printStackTrace();
                log.error("发送熔断了");
                log.debug("调用搜索服务发生熔断降级方法，熔断异常：{}", throwable.getMessage());
                log.debug("username：{}", username);
                return null;
            }

            @Override
            public R<String> updateUserStar(String username, Integer star) {
                throwable.printStackTrace();
                log.error("发送熔断了");
                log.debug("调用搜索服务发生熔断降级方法，熔断异常：{}", throwable.getMessage());
                log.debug("username：{}，star：{}", username, star);
                return null;
            }
        };
    }
}
